package com.cangxuan.manage.controller;


import com.cangxuan.manage.annotation.Check;
import com.cangxuan.manage.annotation.check.Max;
import com.cangxuan.manage.annotation.check.NotNull;
import com.cangxuan.manage.bean.Page;
import com.cangxuan.manage.entity.Goods;
import com.cangxuan.manage.entity.User;
import com.cangxuan.manage.service.IUserService;
import io.swagger.annotations.*;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Author:程佳逸
 * 用户相关接口
 */
@Slf4j
@Api(tags = "用户相关接口")
@RestController
@RequestMapping("user")
public class UserController extends BaseController {
    IUserService userService;

    @Autowired
    public void setUserService(IUserService userService) {
        this.userService = userService;
    }

    @Data
    @ApiModel("用户分页查询body")
    public static class UserPageBody {
        @ApiModelProperty("页码，从1开始")
        @NotNull(message = "请传递pageIndex")
        Integer pageIndex;
        @ApiModelProperty("页大小，就是每页查询的数量，最大为50条")
        @Max(value = 50, message = "pageSize不能大于50")
        Integer pageSize = 10;
        @ApiModelProperty("用户id")
        int id;
        @ApiModelProperty("用户手机号码")
        String mobile;
        @ApiModelProperty("用户姓名")
        String realName;
        @ApiModelProperty("用户身份证号码")
        String idcard;
        @ApiModelProperty("用户实名参数")
        int realNameInfo;
    }

    @Data
    @ApiModel("用户状态修改body")
    public static class ChangeStateBody {
        @ApiModelProperty("用户状态")
        Boolean available;
        @ApiModelProperty("用户id")
        int id;

    }
    @Data
    @ApiModel("用户订阅修改body")
    public static class ChangeSubscribeBody {
        @ApiModelProperty("用户状态")
        Boolean subscribeToTheSalesCalendar;
        @ApiModelProperty("用户id")
        int id;

    }
    @Data
    @ApiModel("是否展示我的藏品修改body")
    public static class ChangeDisplayMyGoodsBody {
        @ApiModelProperty("用户状态")
        Boolean displayMyGoods;
        @ApiModelProperty("用户id")
        int id;

    }
    @Data
    @ApiModel("是否展示我出售的藏品，默认为0body")
    public static class ChangeDisplayMySellGoodsBodyBody {
        @ApiModelProperty("用户状态")
        Boolean displayMySellGoods;
        @ApiModelProperty("用户id")
        int id;

    }

    @PostMapping
    @ApiOperation("用户分页查询")
    public Object page(@Check @RequestBody UserController.UserPageBody userPageBody) {
        System.out.println(userPageBody.getRealNameInfo());
        Page<User> userPage = userService.page(userPageBody.getPageIndex(),
                userPageBody.getPageSize(),
                userPageBody.getId(),
                userPageBody.getMobile(),
                userPageBody.getRealName(),
                userPageBody.getIdcard(),
                userPageBody.getRealNameInfo());
        return success(userPage);
    }


    @GetMapping("isRealNamed")
    @ApiOperation("查询所有已经实名的用户")
    public Object isRealNamed() {
        return success("请求成功", userService.isRealNamed());
    }

    @PostMapping("changeState")
    @ApiOperation("修改用户状态")
    public Object changeState(@Check @RequestBody ChangeStateBody changeStateBody) {
        return success("修改成功", userService.changeState(changeStateBody.getAvailable(), changeStateBody.getId()));
    }

    @GetMapping("selectByUserID")
    @ApiOperation("获取用户资产信息")
    public Object selectByUserID(@RequestParam int userId) {
        return success("请求成功",userService.selectByUserID(userId));

    }
    @PostMapping("changeSubscribe")
    @ApiOperation("修改用户是否订阅")
    public Object changeSubscribe(@Check @RequestBody ChangeSubscribeBody changeSubscribeBody) {
        return success("修改成功", userService.changeSubscribe(changeSubscribeBody.getSubscribeToTheSalesCalendar(), changeSubscribeBody.getId()));
    }
    @PostMapping("changeDisplayMyGoods")
    @ApiOperation("修改用户是否展示藏品")
    public Object changeDisplayMyGoods(@Check @RequestBody ChangeDisplayMyGoodsBody changeDisplayMyGoodsBody) {
        return success("修改成功", userService.changeDisplayMyGoods(changeDisplayMyGoodsBody.getDisplayMyGoods(), changeDisplayMyGoodsBody.getId()));
    }
    @PostMapping("changeDisplayMySellGoods")
    @ApiOperation("修改用户是否展示出售藏品")
    public Object changeDisplayMySellGoods(@Check @RequestBody ChangeDisplayMySellGoodsBodyBody changeDisplayMySellGoodsBodyBody) {
        return success("修改成功", userService.changeDisplayMySellGoods(changeDisplayMySellGoodsBodyBody.getDisplayMySellGoods(), changeDisplayMySellGoodsBodyBody.getId()));
    }
}
